home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / MDIT.ARJ / MDIT.C < prev    next >
C/C++ Source or Header  |  1992-03-31  |  6KB  |  189 lines

  1. /****************************************************************************
  2. Module name: MDIT.C
  3. Programmer : Jeffrey M. Richter & Elvira Peretsman.
  4. Modified   : V. M. Vanderburg & M.T. Peterson, TriTechnologies
  5.                    -    Converted to multithreading
  6.                    -    Removed original comments
  7. ATTRIBUTIONS:
  8.  
  9.     With the exception of the PCthread calls, this code was taken directly
  10.     from the source disk furnished with the Windows Developer's Guide,
  11.     M&T Press, by Jeffrey M. Richter.  I highly recommend Mr. Richter's
  12.     book both for its readability and the structure and quality of the
  13.     code.
  14. *****************************************************************************/
  15. /*
  16. #include "..\nowindws.h"
  17. #undef NOCTLMGR
  18. #undef NOGDI
  19. #undef NOKERNEL
  20. #undef NOMB
  21. #undef NOMDI
  22. #undef NOMENUS
  23. #undef NOMSG
  24. #undef NOSYSMETRICS
  25. #undef NOUSER
  26. #undef NOWINMESSAGES
  27. #undef NOWINSTYLES
  28. */
  29. #include <windows.h>
  30. #include "mdit.h"        /* includes pcthread.h */
  31.  
  32. char   g_szAppName[] = "PCthreads(tm) for Windows";
  33. HANDLE g_hInstance = NULL;
  34. HANDLE g_hAccelTable = NULL;
  35. HWND   g_hWndMDITClient = NULL;
  36.  
  37. pcthread_attr_t g_th_attr;
  38.  
  39. /************************* Main Application Loop ****************************/
  40.    
  41. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  42.                     LPSTR lpszCmdLine, int nCmdShow) {
  43.    MSG msg;
  44.    HWND hWndFrame;
  45.  
  46.    if (hPrevInstance != NULL) 
  47.    {
  48.       MessageBox(NULL, "MDIT application is already running.", g_szAppName,
  49.          MB_OK | MB_ICONINFORMATION);
  50.       return(0);
  51.    }
  52.  
  53.     /*
  54.      *   --   These next two calls create and initialize a handle to
  55.      *        a thread attributes object.  When this attributes object
  56.      *        is passed to the pcthread_create() routine (see thread.c),
  57.      *        it will cause the pcthread kernel to create a thread with
  58.      *        a stack size of 512 words, or 1024 bytes.
  59.      */
  60.      
  61.    pcthread_attr_create(&g_th_attr);
  62.    pcthread_attr_setstacksize(&g_th_attr, 512 );
  63.    g_hInstance = hInstance;
  64.    
  65.    if (!RegisterFrameWndClass()) 
  66.          return(0);
  67.    
  68.    if (!RegisterThreadWndClass()) 
  69.          return(0);
  70.    
  71.    hWndFrame = CreateWindow("Frame", g_szAppName,
  72.       WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_MAXIMIZE | WS_VISIBLE |
  73.       WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
  74.       CW_USEDEFAULT, nCmdShow, CW_USEDEFAULT, CW_USEDEFAULT,
  75.       NULL, NULL, g_hInstance, NULL);
  76.  
  77.    if (hWndFrame == NULL) 
  78.          return(0);
  79.  
  80.     /*
  81.      *   --   Multithreaded Windows applications are characterized
  82.      *        by heavy usage of the PeekMessage() service rather than
  83.      *        the GetMessage() service.  This is because the GetMessage()
  84.      *        service blocks all threads until a message is available.
  85.      *
  86.      *        Note also the presence of the ubiguitous pcthread_yield()
  87.      *        function.  This allows other threads to run (but does not
  88.      *        allow other window apps to run, i.e., it does for threads
  89.      *        what Yield() does for other Win Apps).
  90.      */
  91.      
  92.    for (;;)
  93.    {
  94.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
  95.       {
  96.          if (!TranslateMDISysAccel(g_hWndMDITClient, &msg)) 
  97.          {
  98.             if (g_hAccelTable == NULL || !TranslateAccelerator(hWndFrame, g_hAccelTable, &msg)) 
  99.             {
  100.                TranslateMessage(&msg);
  101.                DispatchMessage(&msg);
  102.             }
  103.          }
  104.       }
  105.       if (msg.message == WM_QUIT)
  106.       {
  107.          break;
  108.       }
  109.       pcthread_yield();
  110.    }
  111.  
  112.    return(msg.wParam);
  113. }
  114.  
  115. HWND FAR PASCAL CreateMDITChild (LPSTR szClassName, LPSTR szWindowName,
  116.                DWORD dwStyle, short x, short y, short nWidth, short nHeight,
  117.                HWND hWndMDITClient, HANDLE hInstance, LONG lParam) 
  118. {
  119.    MDICREATESTRUCT cs;
  120.    HWND hWndChild;
  121.    th_list_p_t th_p;
  122.  
  123.    cs.szClass = szClassName;
  124.    cs.szTitle = szWindowName;
  125.    cs.hOwner  = hInstance;
  126.    cs.x       = x;
  127.    cs.y       = y;
  128.    cs.cx      = nWidth;
  129.    cs.cy      = nHeight;
  130.    cs.style   = dwStyle;
  131.    cs.lParam   = lParam;
  132.    hWndChild = (HWND) SendMessage(hWndMDITClient, WM_MDICREATE,
  133.                            0, (LONG) (LPMDICREATESTRUCT) &cs);
  134.    
  135.    return(hWndChild);
  136. }
  137.  
  138. void FAR PASCAL ChangeMDITMenu (HWND hWndFrame, HWND hWndClient,
  139.          HMENU hMenuNew, WORD wMenuID) 
  140. {
  141.    WORD wCount;
  142.    HMENU hSubMenu = 0;
  143.  
  144.    wCount = GetMenuItemCount(hMenuNew);
  145.    
  146.    while (wCount) 
  147.    {
  148.       hSubMenu = GetSubMenu(hMenuNew, wCount - 1);
  149.       if ((int) GetMenuState(hSubMenu, wMenuID, MF_BYCOMMAND) != -1)
  150.          break;
  151.       wCount--;
  152.    }
  153.    
  154.    SendMessage(hWndClient, WM_MDISETMENU, 0, MAKELONG(hMenuNew, hSubMenu));
  155.    DrawMenuBar(hWndFrame);
  156. }
  157.  
  158. BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) 
  159. {
  160.    char szBuffer[100];
  161.    BOOL fProcessed = TRUE;
  162.  
  163.    switch (wMsg) 
  164.    {
  165.       case WM_INITDIALOG:
  166.          wsprintf(szBuffer, "%s at %s", (LPSTR) __DATE__, (LPSTR) __TIME__);
  167.          SetWindowText(GetDlgItem(hDlg, ID_VERSION), szBuffer);
  168.          break;
  169.  
  170.       case WM_COMMAND:
  171.          switch (wParam) 
  172.          {
  173.             case IDOK: case IDCANCEL:
  174.                if (HIWORD(lParam) == BN_CLICKED)
  175.                   EndDialog(hDlg, wParam);
  176.                break;
  177.  
  178.             default:
  179.                break;
  180.          }
  181.          break;
  182.  
  183.       default:
  184.          fProcessed = FALSE; break;
  185.    }
  186.  
  187.    return(fProcessed);
  188. }
  189.